package com.burstly.lib.component.networkcomponent.greystripe;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;
import com.burstly.lib.component.networkcomponent.AbstractNetworkConfigurator;
import com.burstly.lib.util.LoggerExt;
import com.burstly.lib.util.ManifestValidator;
import com.burstly.lib.util.ManifestValidator.ValidationResults;
import com.burstly.lib.util.Utils;
import com.greystripe.sdk.GSSdkInfo;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

class GreystripeConfigurator extends AbstractNetworkConfigurator<Object>
{
  public static final String AD_SIZE = "adSize";
  static final String AD_SIZE_300_250 = "300x250";
  static final String AD_SIZE_320_50 = "320x50";
  static final String AD_SIZE_728_90 = "728x90";
  static final String AD_SIZE_INTERSTITIAL = "interstitial";
  public static final String APP_ID = "appId";
  private static final List<String> GEO_TARGETING_PERMISSIONS = Arrays.asList(new String[] { "android.permission.ACCESS_FINE_LOCATION", "android.permission.ACCESS_COARSE_LOCATION" });
  private static final LoggerExt LOG;
  private static final String TAG = GreystripeConfigurator.class.getSimpleName();
  private String mAdSize;
  private String mAppId;
  private String mGeoLocationParams;
  private boolean mIsInterstitial;

  static
  {
    LOG = LoggerExt.getInstance();
  }

  static String getAdSize(String paramString)
  {
    if ("320x50".equalsIgnoreCase(paramString))
      return "320x50";
    if ("300x250".equalsIgnoreCase(paramString))
      return "300x250";
    if ("728x90".equalsIgnoreCase(paramString))
      return "728x90";
    if ("interstitial".equalsIgnoreCase(paramString))
      return "interstitial";
    return "320x50";
  }

  private static boolean getUseGeoLocation(String paramString)
  {
    try
    {
      boolean bool1 = ManifestValidator.customValidate(null, GEO_TARGETING_PERMISSIONS, null).getMandatoryPermissions().isEmpty();
      boolean bool2 = false;
      if (bool1)
      {
        boolean bool3 = "true".equalsIgnoreCase(paramString);
        bool2 = false;
        if (bool3)
          bool2 = true;
      }
      return bool2;
    }
    catch (PackageManager.NameNotFoundException localNameNotFoundException)
    {
      LOG.logDebug(TAG, Log.getStackTraceString(localNameNotFoundException), new Object[0]);
    }
    return false;
  }

  private void setAdSize(Map<String, ?> paramMap)
  {
    this.mAdSize = getAdSize((String)paramMap.get("adSizeCodeValue"));
    Object localObject = paramMap.get("adSize");
    if (localObject != null)
      this.mAdSize = getAdSize((String)localObject);
  }

  private void setInterstitial(Map<String, ?> paramMap)
  {
    Object localObject = paramMap.get("isCodeValueInterstitial");
    if (localObject != null)
      this.mIsInterstitial = ((Boolean)localObject).booleanValue();
    if ((this.mAdSize != null) && ("interstitial".equals(this.mAdSize)))
      this.mIsInterstitial = true;
  }

  protected void applyClientTargetingParamsToNetwork(Map<String, String> paramMap)
  {
  }

  public void configure(Object paramObject)
  {
  }

  String getAdSize()
  {
    return this.mAdSize;
  }

  String getAppId()
  {
    return this.mAppId;
  }

  boolean isInterstitial()
  {
    return this.mIsInterstitial;
  }

  public void readParameters(Map<String, ?> paramMap)
    throws IllegalArgumentException
  {
    applyClientTargetingIfAllowed(paramMap);
    Object localObject1 = paramMap.get("appId");
    Utils.checkNotNull(localObject1, "appId can not be null");
    this.mAppId = ((String)localObject1).trim();
    setAdSize(paramMap);
    setInterstitial(paramMap);
    if ((!"300x250".equals(this.mAdSize)) && (!"320x50".equals(this.mAdSize)) && (!"728x90".equals(this.mAdSize)) && (!"interstitial".equals(this.mAdSize)))
      throw new IllegalArgumentException("Unknown adSize value provided");
    Object localObject2 = paramMap.get("useGeoLocation");
    if (localObject2 != null)
      this.mGeoLocationParams = ((String)localObject2);
  }

  public void updateLocation(Context paramContext)
  {
    LocationManager localLocationManager;
    if ((this.mGeoLocationParams != null) && (getUseGeoLocation(this.mGeoLocationParams)))
      localLocationManager = (LocationManager)paramContext.getSystemService("location");
    Location localLocation1;
    Location localLocation2;
    try
    {
      Location localLocation5 = localLocationManager.getLastKnownLocation("gps");
      localLocation1 = localLocation5;
    }
    catch (IllegalArgumentException localIllegalArgumentException1)
    {
      try
      {
        while (true)
        {
          Location localLocation4 = localLocationManager.getLastKnownLocation("network");
          localLocation2 = localLocation4;
          if ((localLocation1 == null) || (localLocation2 == null))
            break label144;
          if (localLocation1.getTime() <= localLocation2.getTime())
            break;
          localLocation3 = localLocation1;
          if (localLocation3 != null)
            GSSdkInfo.updateLocation(localLocation3);
          return;
          localIllegalArgumentException1 = localIllegalArgumentException1;
          LOG.logDebug(TAG, "Failed to retrieve GPS location: No GPS found", new Object[0]);
          localLocation1 = null;
        }
      }
      catch (IllegalArgumentException localIllegalArgumentException2)
      {
        while (true)
        {
          LOG.logDebug(TAG, "Failed to retrieve network location: No network provider found", new Object[0]);
          localLocation2 = null;
          continue;
          localLocation3 = localLocation2;
        }
      }
    }
    label144: if (localLocation1 != null);
    for (Location localLocation3 = localLocation1; ; localLocation3 = localLocation2)
      break;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.networkcomponent.greystripe.GreystripeConfigurator
 * JD-Core Version:    0.6.2
 */